<?php
class HotPsyTests extends CWidget {
	public $topics;
	
	public function init() {
        $criteria = new CDbCriteria;
        $createdAt = time()-24*3600*60;
        $criteria->condition = 'createdAt > '.$createdAt;
        $criteria->order = 'testedCount DESC';
        $criteria->limit = 10;
        $this->topics = TestTopics::model()->published()->findAll($criteria);
        if(($limit = 10 - count($this->topics)) > 0) {
        	$criteria = new CDbCriteria;
        	$criteria->limit = $limit;
        	$criteria->order = 'topicId DESC';
        	$topics = TestTopics::model()->published()->findAll($criteria);
        	$this->topics = array_merge($this->topics, $topics);
        }
	}
	
	public function run() {
		$this->renderContent();
	}

	public function renderContent($return = false) {
		return $this->render('hot-psytests', array('topics' => $this->topics), $return);
	}
}
